<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : musilka.xsl
    Created on : 28. duben 2011, 13:46
    Author     : Jan Šťastný
    Description:
        Parsing data from http://www.ksomega.cz/?a=musilka-program 
-->


<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://code.google.com/p/kalkon/internalConcerts">

    <xsl:output method="xml"
                encoding="UTF-8"
                indent="yes"
                media-type="text/xml"/>
    

<!-- Create concerts  -->
    <xsl:template match="/html">
        <concerts>
            <xsl:attribute name="id">musilka</xsl:attribute>
            <xsl:apply-templates select="//div[@class='musilka_prg_polozka']"/>
        </concerts>
    </xsl:template>

<!--  Parse concert  -->
    <xsl:template match="//div[@class='musilka_prg_polozka']">
        <concert>
            <xsl:apply-templates select="div[@class='musilka_prg_detail']"/>
            <xsl:apply-templates select="div[@class='musilka_prg_detail']/div[1]"/>
            <location><xsl:text>KS Omega, Musilova 2a, Brno Husovice</xsl:text></location>
            <xsl:apply-templates select="div[@class='musilka_prg_den']"/>
        </concert>
    </xsl:template>

<!--  Parse day_start and time_start  -->
    <xsl:template match="//div[@class='musilka_prg_den']">
        <xsl:variable name="year"><xsl:value-of select="substring(b,string-length(b)-4,4)"/></xsl:variable>
        <xsl:variable name="month"><xsl:value-of select="substring-before(substring-after(b,'. '),'. ')"/></xsl:variable>
        <xsl:variable name="day"><xsl:value-of select="substring-before(b,'.')"/></xsl:variable>
        <xsl:variable name="timetoparse"><xsl:value-of select="normalize-space(child::text()[last()-1])" /></xsl:variable>
        <xsl:variable name="hours"><xsl:value-of select="substring-before($timetoparse,':')"/></xsl:variable>
        <xsl:variable name="minutes"><xsl:value-of select="substring(substring-after($timetoparse,':'),1,2)"/></xsl:variable>
        <xsl:variable name="seconds"><xsl:text>00</xsl:text></xsl:variable> <!-- Set SECONDS -->
        <day_start><xsl:value-of select="concat($year,$month,$day)"/></day_start>
        <time_start><xsl:value-of select="concat($hours,$minutes,$seconds)"/></time_start>
    </xsl:template>

    <xsl:template match="//div[@class='musilka_prg_detail']">
        <title><xsl:value-of select="h4"/></title>
    </xsl:template>

    <xsl:template match="//div[@class='musilka_prg_detail']/div">
        <description><xsl:value-of select="normalize-space(.)"/></description>
    </xsl:template>

</xsl:stylesheet>
